﻿using Big_Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Big_Data.Data_Base_Excel.Sante
{
    class RequeteSante
    {
        public string datedebut { get; set; }
        public string datefin { get; set; }
        public string choix_pays { get; set; }
        public string DATES { get; set; }
        public string VALEURS { get; set; }
        public string PAYS { get; set; }

        public int GetIdDate(string ref_date)
        {
            using (Offres_facteursContainer entities = new Offres_facteursContainer())
            {
                return (from id in entities.DateSanteSet
                        where id.Date.Equals(ref_date)
                        select id.Id).FirstOrDefault();
            }
        }

        

        public List<RequeteSante> SelectDepenseSante()
        {
            using (Offres_facteursContainer entities = new Offres_facteursContainer())
           {
                string[] splitDateDebut = datedebut.Split('-');
                string[] splitDateFin = datefin.Split('-');

                int debut = Int32.Parse(splitDateDebut[0]);
                int fin = Int32.Parse(splitDateFin[0]);

                return (from dep in entities.DepenseSanteChargePatientSet.AsEnumerable()
                        join date in entities.DateSanteSet
                            on dep.DateSanteId equals date.Id
                        join pay in entities.PaysSanteSet
                            on dep.PaysSanteId equals pay.Id
                        let split_date = date.Date.Split('-')
                        let convert_date = Int32.Parse(split_date[0])
                        where (pay.Pays.Equals(choix_pays)
                           && (convert_date >= debut) && (convert_date <= fin)
                           && (!dep.Valeurs.Contains("..")))
                        select new RequeteSante()
                        {
                            DATES = date.Date,
                            VALEURS = dep.Valeurs,
                            PAYS = pay.Pays
                        }).ToList();
            }
        }
    }
}
